package com.lunz.machine.fragment;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import androidx.core.content.ContextCompat;

import com.lunz.machine.R;
import com.lunz.machine.base.BaseFragment;
import com.lunz.machine.widget.TimePopupWindow;

import butterknife.InjectView;
import butterknife.OnClick;

/**
 * @ClassName HomeFragment
 * @Description 首页Fragment-未开始
 * @Author ：WangZhuang
 * @Date : 2020/10/13 13:24
 * @Version :
 */
public class HomeNoStartFragment extends BaseFragment {
    @InjectView(R.id.llyout_time)
    LinearLayout llyout_time;
    @InjectView(R.id.llyout_filtrate)
    LinearLayout llyout_filtrate;
    @InjectView(R.id.v_split_line)
    View v_split_line;

    @Override
    public void onCreateView(ViewGroup container) {
        setView(R.layout.fragment_home_nostart, container, false, true);
    }

    @OnClick({R.id.llyout_time, R.id.llyout_filtrate})
    public void OnClick(View v) {
        switch (v.getId()) {
            case R.id.llyout_time: {//根据时间选择
                showOrderItemsPPWindow();
            }
            break;
            case R.id.llyout_filtrate: {//根据作业类型筛选
                showFiltratePWindow();
            }
            break;
        }
    }

    void showOrderItemsPPWindow() {
        final View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.tppw_time_pick_type, null, false);
        final TimePopupWindow window = new TimePopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        window.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.gray_transparent)));
        window.setOutsideTouchable(true);
        window.setTouchable(true);
        window.showAsDropDown(v_split_line);
        window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));

        LinearLayout linearLayout = contentView.findViewById(R.id.full_llayout);
//        linearLayout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                window.dismiss();
//            }
//        });
        window.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                window.dismiss();
            }
        });
    }

    void showFiltratePWindow() {
        final View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.tppw_pfiltrate, null, false);
        final TimePopupWindow window = new TimePopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        window.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.gray_transparent)));
        window.setOutsideTouchable(true);
        window.setTouchable(true);
        window.showAsDropDown(v_split_line);
        window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));

        LinearLayout linearLayout = contentView.findViewById(R.id.full_llayout);
//        linearLayout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                window.dismiss();
//            }
//        });
        window.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                window.dismiss();
            }
        });
    }
}
